﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Proggy.Web.Cms.Membership;
using System.Web.Configuration;
using System.Security.Principal;
using Proggy.Data.Entities;
using Proggy.Web.Cms.ViewModels;

namespace Proggy.Web.Cms.Repositories.Membership
{
    /// <summary>
    /// Membership repository
    /// </summary>
    public interface IMembershipRepository
    {
        /// <summary>
        /// Get member from IPrinciple object
        /// </summary>
        /// <param name="iPrincipal"></param>
        /// <returns></returns>
        ProggyMember GetMember(IPrincipal iPrincipal, bool activeOnly);

        /// <summary>
        /// Get member from the username
        /// </summary>
        /// <param name="iPrincipal"></param>
        /// <returns></returns>
        ProggyMember GetMember(string username, bool activeOnly);

        /// <summary>
        /// Returns authentication section from web.config
        /// </summary>
        /// <returns></returns>
        AuthenticationSection ConfigAuthenticationSection { get; }

        /// <summary>
        /// Checks groups against current member
        /// </summary>
        /// <param name="proggyMember"></param>
        /// <param name="_groups"></param>
        /// <returns></returns>
        bool GetAuthOk(ProggyMember proggyMember, string[] groups);

        /// <summary>
        /// Returns groups for user
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        IEnumerable<Group> GetProggyGroupsForMember(string username);

        /// <summary>
        /// Returns true if user is authenticated ok
        /// </summary>
        /// <param name="model"></param>
        /// <param name="errorMsg"></param>
        /// <param name="setLastLogon"></param>
        /// <returns></returns>
        bool GetFormsAuthenticationOk(ProggyFormsAuthenticationLogonViewModel model, bool setLastLogon, ref string errorMsg);

        /// <summary>
        /// Returns view model
        /// </summary>
        /// <returns></returns>
        ChangePasswordViewModel GetChangePasswordViewModel();

        /// <summary>
        /// If valid, changes password and re-logs in
        /// </summary>
        /// <param name="model"></param>
        /// <param name="errorMsg"></param>
        /// <param name="currentUsername"></param>
        /// <returns></returns>
        bool GetChangePasswordOk(ChangePasswordViewModel model, string currentUsername, ref string errorMsg);

        /// <summary>
        /// Returns view model
        /// </summary>
        /// <returns></returns>
        RegisterViewModel GetRegisterViewModel();

        /// <summary>
        /// Register new member and send activation email
        /// </summary>
        /// <param name="model"></param>
        /// <param name="activationUrl"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool GetRegisterNewMemberOk(RegisterViewModel model, string activationUrl, ref string errorMsg);

        /// <summary>
        /// Send activation email
        /// </summary>
        /// <param name="email"></param>
        /// <param name="activationUrl"></param>
        /// <param name="guid"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool SendActivationEmail(string email, string activationUrl, Guid guid, ref string errorMsg);

        /// <summary>
        /// Activate membership
        /// </summary>
        /// <param name="activationCode"></param>
        void ActivateMembership(string activationCode);

        /// <summary>
        /// Forgotten details view model
        /// </summary>
        /// <returns></returns>
        ForgotViewModel GetForgotViewModel();

        /// <summary>
        /// Reset password and send details
        /// </summary>
        /// <param name="model"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool GetResendDetailsOk(ForgotViewModel model, ref string errorMsg);

        /// <summary>
        /// Logon view model
        /// </summary>
        /// <param name="returnUrl"></param>
        /// <returns></returns>
        ProggyFormsAuthenticationLogonViewModel GetLogonViewModel(string returnUrl);

        /// <summary>
        /// Returns all groups
        /// </summary>
        /// <returns></returns>
        IQueryable<Group> GetGroups();

        /// <summary>
        /// Returns all members
        /// </summary>
        /// <param name="activeOnly"></param>
        /// <returns></returns>
        IQueryable<ProggyMember> GetAllMembers(bool activeOnly);

        /// <summary>
        /// Return group member
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        AddGroupMembersViewModel GetAddGroupMemberViewModel(int groupId);

        /// <summary>
        /// Add members
        /// </summary>
        /// <param name="model"></param>
        /// <param name="currentUsername"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool GetAddMembersOk(AddGroupMembersViewModel model, string currentUsername, ref string errorMsg);

        /// <summary>
        /// Remove group member
        /// </summary>
        /// <param name="groupMemberId"></param>
        void RemoveGroupMember(int groupMemberId);

        /// <summary>
        /// Get group view model
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        GroupViewModel GetGroupViewModel(int groupId);

        /// <summary>
        /// Add group
        /// </summary>
        /// <param name="groupName"></param>
        /// <param name="currentUsername"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool GetAddGroupOk(string groupName, string currentUsername, ref string errorMsg);
    }
}
